using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Bll
{
	class CDeliveryManage
	{
		public static CDelivery CreateDelivery()
       {      
           return   new CDelivery();
       }
	   
	   public static CDelivery Save(CDelivery delivery)
	   {
			try
           {
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_AddDelivery", delivery.ID, delivery.commodityID, delivery.ownerID, delivery.buyerID, delivery.status, delivery.statusTime, delivery.orderServer, delivery.orderNum);
             
				if(0 == num)
                   return null;
                return delivery;
           }
           catch (Exception e)
           {
               return null;
           }
	   }
	   
	   public static bool Update(CDelivery delivery)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_SaveDelivery", delivery.ID, delivery.commodityID, delivery.ownerID, delivery.buyerID, delivery.status, delivery.statusTime, delivery.orderServer, delivery.orderNum);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   public static bool Delete(CDelivery delivery)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_RemoveDelivery", delivery.ID);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   static CDelivery GetDelivery(String ID)
	   {
			try
           {
               
               SqlDataReader reader= BLL.SqlHelper.ExecuteReader(CConnection.getConnString(), "sp_GetDelivery", ID);
               if (reader.NextResult())
               { 
					CDelivery delivery = new CDelivery();
					delivery.commodityID = reader["commodityID"].ToString();
					delivery.ownerID = reader["ownerID"].ToString();
					delivery.buyerID = reader["buyerID"].ToString();
					//delivery.status = reader["status"].ToString();
					//delivery.statusTime = reader["statusTime"].ToString();
					delivery.orderServer = reader["orderServer"].ToString();
					delivery.orderNum = reader["orderNum"].ToString();
					
					reader.Close();
					return delivery;
               }
			   reader.Close();
               return null;
           }
           catch (Exception e)
           {

               //reader.Close();
               return null;
           }
	   }
	}
}